import ths_vol as ths
# ths.zt()
from get_data import Altas_db
import pandas as pd
from get_data import  other
_1_, time_, _2_ = other.time_start()
day_=time_
print("获取时间",day_)
df=Altas_db._readdf("iwencai/zt","{}".format(day_))

if len(df)==0:
    ths.zt()
    df=Altas_db._readdf("iwencai/zt","{}".format(day_))

print(df)
df=df.drop_duplicates()
print(df)
#获得涨停原因
df_reason=df['涨停原因类别'].str.split('+', expand=True)
df=df.join(df_reason)
#涨停原因统计
temp=pd.DataFrame()
for i in range(len(df_reason.columns)):
    _df=df_reason[i]
    temp=pd.concat([temp,_df])
_df_count=temp.value_counts()
_df_count_3=_df_count[_df_count>=3]

"""_df_count
ST板块     28
新能源汽车    19
汽车零部件    15
军工       10
"""
df_BK=pd.DataFrame()
df_BK_sum=[]
for i_num in range(len(_df_count)):
    temp_bk=pd.DataFrame()
    print("index_name",_df_count.index[i_num][0])
    for i in range(len(_df_count)):
        try:
            _df_bk=df[df[i]=="{}".format(_df_count.index[i_num][0])]
            print(_df_bk)
            temp_bk=pd.concat([temp_bk,_df_bk])

        except:
            pass
    print(temp_bk)
    df_BK_sum.append(temp_bk["资金流向"].sum())
    df_BK=pd.concat([df_BK,temp_bk])
# for i_num in range(len(_df_count)):
#     print(_df_count.index[i_num][0])
#     for i_name in len:

df_BK.to_csv("db_temp/ths_zt_dic/{}.json".format(day_))
df1=pd.DataFrame()
lst=_df_count.index.tolist()
res = [x for x, in lst]
df1["BK"]=res
df1["num"]=_df_count.tolist()
df1["sum_"]=df_BK_sum
print(df1)
print(_df_count_3)
